import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class Comprehension {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            students.add(createStudent(18 + i));
        }
        for (Student student : students) {
            Optional<Student> optional = Optional.ofNullable(student);
            Integer age = optional
            .filter(stu-> stu.getAge() > 20)
            .map(Student::getAge)
            .orElse(0);
            System.out.println(age);
            if (age > 20) {
                System.out.println(student.getName());
            }
        }
    }

    private static Student createStudent(Integer age) {
        System.out.println("create student");
        return new Student(1 + age, "xxt" + age, age);
    }
}
